<template>
  <div id="app">
    <!-- 顶部导航栏 -->
    <header class="admin-header">
      <div class="header-left">
        <button class="menu-toggle" @click="toggleSidebar">
          <i class="icon">☰</i>
        </button>
        <h1 class="admin-title">企业管理后台</h1>
      </div>
      <div class="header-right">
        <div class="user-info">
          <span class="user-avatar">👤</span>
          <span class="user-name">管理员</span>
          <button class="logout-btn" @click="logout">退出</button>
        </div>
      </div>
    </header>

    <div class="admin-layout">
      <!-- 侧边栏 -->
      <aside class="admin-sidebar" :class="{ collapsed: sidebarCollapsed }">
        <nav class="sidebar-nav">
          <div class="nav-section">
            <div class="nav-title">系统管理</div>
            <ul class="nav-list">
              <li class="nav-item">
                <router-link to="/" class="nav-link" active-class="active" exact>
                  <i class="nav-icon">👥</i>
                  <span class="nav-text">用户管理</span>
                </router-link>
              </li>
              <li class="nav-item">
                <router-link to="/world" class="nav-link" active-class="active">
                  <i class="nav-icon">🔧</i>
                  <span class="nav-text">系统设置</span>
                </router-link>
              </li>
            </ul>
          </div>

          <div class="nav-section">
            <div class="nav-title">内容管理</div>
            <ul class="nav-list">
              <li class="nav-item">
                <router-link to="/content" class="nav-link" active-class="active">
                  <i class="nav-icon">📝</i>
                  <span class="nav-text">文章管理</span>
                </router-link>
              </li>
              <li class="nav-item">
                <router-link to="/media" class="nav-link" active-class="active">
                  <i class="nav-icon">🖼️</i>
                  <span class="nav-text">媒体库</span>
                </router-link>
              </li>
            </ul>
          </div>

          <div class="nav-section">
            <div class="nav-title">数据统计</div>
            <ul class="nav-list">
              <li class="nav-item">
                <router-link :to="{ name: 'datareport' }" class="nav-link" active-class="active">
                  <i class="nav-icon">🖼️</i>
                  <span class="nav-text">数据报表</span>
                </router-link>
              </li>
              <li class="nav-item">
                <a href="#" class="nav-link">
                  <i class="nav-icon">💰</i>
                  <span class="nav-text">财务统计</span>
                </a>
              </li>
            </ul>
          </div>
        </nav>
      </aside>

      <!-- 主内容区域 -->
      <main class="admin-main">
        <div class="main-content">
          <router-view />
        </div>
      </main>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'App',
    data() {
      return {
        sidebarCollapsed: false,
      };
    },
    methods: {
      toggleSidebar() {
        this.sidebarCollapsed = !this.sidebarCollapsed;
      },
      logout() {
        console.log('logout');
      },
    },
  };
</script>

<style>
  * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }

  body {
    font-family:
      -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #f5f7fa;
    color: #333;
    overflow-x: hidden;
  }

  #app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
  }

  /* 顶部导航栏 */
  .admin-header {
    height: 60px;
    background: #fff;
    border-bottom: 1px solid #e8eaec;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
  }

  .header-left {
    display: flex;
    align-items: center;
    gap: 16px;
  }

  .menu-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.3s ease;
    color: #666;
  }

  .menu-toggle:hover {
    background: #f5f7fa;
  }

  .menu-toggle .icon {
    font-size: 18px;
  }

  .admin-title {
    font-size: 20px;
    font-weight: 600;
    color: #1890ff;
  }

  .header-right {
    display: flex;
    align-items: center;
  }

  .user-info {
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .user-avatar {
    width: 32px;
    height: 32px;
    background: #1890ff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 14px;
  }

  .user-name {
    font-weight: 500;
    color: #333;
  }

  .logout-btn {
    padding: 6px 12px;
    background: #f5f5f5;
    border: 1px solid #d9d9d9;
    border-radius: 4px;
    color: #666;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 12px;
  }

  .logout-btn:hover {
    background: #fff;
    border-color: #1890ff;
    color: #1890ff;
  }

  /* 主布局容器 */
  .admin-layout {
    margin-top: 60px;
    display: flex;
    min-height: calc(100vh - 60px);
  }

  /* 侧边栏 */
  .admin-sidebar {
    width: 240px;
    background: #fff;
    border-right: 1px solid #e8eaec;
    transition: all 0.3s ease;
    overflow-y: auto;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.05);
  }

  .admin-sidebar.collapsed {
    width: 64px;
  }

  .sidebar-nav {
    padding: 16px 0;
  }

  .nav-section {
    margin-bottom: 24px;
  }

  .nav-title {
    padding: 8px 20px;
    font-size: 12px;
    color: #999;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: opacity 0.3s ease;
  }

  .admin-sidebar.collapsed .nav-title {
    opacity: 0;
    padding: 8px 0;
  }

  .nav-list {
    list-style: none;
  }

  .nav-item {
    margin: 2px 8px;
  }

  .nav-link {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    color: #666;
    text-decoration: none;
    border-radius: 6px;
    transition: all 0.3s ease;
    position: relative;
    gap: 12px;
  }

  .nav-link:hover {
    background: #f0f9ff;
    color: #1890ff;
  }

  .nav-link.active {
    background: #e6f7ff;
    color: #1890ff;
    font-weight: 500;
  }

  .nav-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: #1890ff;
    border-radius: 0 2px 2px 0;
  }

  .nav-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
  }

  .nav-text {
    transition: opacity 0.3s ease;
    white-space: nowrap;
  }

  .admin-sidebar.collapsed .nav-text {
    opacity: 0;
    width: 0;
    overflow: hidden;
  }

  .admin-sidebar.collapsed .nav-link {
    justify-content: center;
    padding: 12px;
  }

  /* 主内容区域 */
  .admin-main {
    flex: 1;
    background: #f5f7fa;
    min-height: calc(100vh - 60px);
  }

  .main-content {
    padding: 24px;
    max-width: 1400px;
    margin: 0 auto;
  }

  /* 响应式设计 */
  @media (max-width: 768px) {
    .admin-header {
      padding: 0 12px;
    }

    .admin-title {
      font-size: 18px;
    }

    .user-name {
      display: none;
    }

    .admin-sidebar {
      position: fixed;
      left: 0;
      top: 60px;
      height: calc(100vh - 60px);
      z-index: 999;
      transform: translateX(-100%);
      transition: transform 0.3s ease;
    }

    .admin-sidebar:not(.collapsed) {
      transform: translateX(0);
    }

    .admin-main {
      margin-left: 0;
    }

    .main-content {
      padding: 16px;
    }
  }

  @media (max-width: 480px) {
    .header-left .admin-title {
      display: none;
    }

    .main-content {
      padding: 12px;
    }
  }

  /* 滚动条样式 */
  .admin-sidebar::-webkit-scrollbar {
    width: 4px;
  }

  .admin-sidebar::-webkit-scrollbar-track {
    background: transparent;
  }

  .admin-sidebar::-webkit-scrollbar-thumb {
    background: #d9d9d9;
    border-radius: 2px;
  }

  .admin-sidebar::-webkit-scrollbar-thumb:hover {
    background: #bfbfbf;
  }
</style>
